Super Media Element
A custom element that helps save alienated player API's to bring back their true inner HTMLMediaElement API, or to extend a native media element like <audio>
or <video>
.
Usage
import { SuperVideoElement } from 'super-media-element';
class MyVideoElement extends SuperVideoElement {
constructor() {
super();
this.loadComplete = new Promise((resolve) => {
this.loadResolve = resolve;
});
}
async attributeChangedCallback(attrName, oldValue, newValue) {
if (attrName === 'src' && newValue) {
this.load();
return;
}
super.attributeChangedCallback(attrName, oldValue, newValue);
}
async load() {
if (this.hasLoaded) {
this.loadComplete = new Promise((resolve) => {
this.loadResolve = resolve;
});
}
this.hasLoaded = true;
await Promise.resolve();
this.loadResolve();
}
get nativeEl() {
return this.querySelector('.loaded-video-element');
}
get src() {
return this.getAttribute('src');
}
set src(val) {
if (this.src == val) return;
this.setAttribute('src', val);
}
}
if (!globalThis.customElements.get('my-video')) {
globalThis.customElements.define('my-video', MyVideoElement);
globalThis.MyVideoElement = MyVideoElement;
}
export { MyVideoElement };
Related